package br.com.wuo.karina.view;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import br.com.wuo.karina.model.dao.ProfessorDao;
import br.com.wuo.karina.model.dao.impl.ProfessorDaoImpl;

public class PagamentosTopPane extends JPanel {
	
	private static final long serialVersionUID = 1L;

	private JLabel lblProfessor;

	private JComboBox<String> cmbBxProfessor;
	
	private JButton btnCalcular;
	
	private ProfessorDao professorDao;
	
	public PagamentosTopPane() {
		initialize();
	}

	private void initialize() {
		
		lblProfessor = new JLabel("Professor:");
		
		professorDao = new ProfessorDaoImpl();
		cmbBxProfessor = new JComboBox<String>();
		populateCombos();
		
		btnCalcular = new JButton("Calcular");
		
		setLayout(new GridBagLayout());
		setBorder(BorderFactory.createEtchedBorder());
		
		GridBagConstraints gc = new GridBagConstraints();
		
		gc.gridx = 0;
		gc.gridy = 0;
		gc.weighty = 0.2;
		gc.anchor = GridBagConstraints.LAST_LINE_END;
		gc.insets = new Insets(15, 0, 20, 5);
		add(lblProfessor, gc);
		
		gc.gridx = 1;
		gc.anchor = GridBagConstraints.LAST_LINE_START;
		gc.insets = new Insets(15, 0, 15, 0);
		add(cmbBxProfessor, gc);
		
		gc.gridx = 2;
		gc.anchor = GridBagConstraints.LAST_LINE_START;
		gc.insets = new Insets(15, 5, 15, 0);
		add(btnCalcular, gc);
		
	}
	
	private void populateCombos() {
		try {
			ArrayList<String> professores = professorDao.getAllProfessor();
			
			for(String professor:professores){
				cmbBxProfessor.addItem(professor);
			}
			
			cmbBxProfessor.setSelectedIndex(-1);
			
		} catch (SQLException e) {
			e.printStackTrace();
		}		
	}

}
